<?php

namespace Database\Seeders;

use Carbon\Carbon;
use Flynsarmy\CsvSeeder\CsvSeeder;
use Illuminate\Support\Facades\DB;

class CountrySeeder extends CsvSeeder
{
    public function __construct()
    {
        $this->table = 'countries';
        $this->filename = base_path().'/database/seeders/csvs/italian-countries-iso2.csv';
        $this->offset_rows = 1;
        $this->mapping = [
            0 => 'name',
            1 => 'iso_639_1',
        ];
        $this->should_trim = true;
    }

    public function run()
    {
        parent::run();
        // this.timestamps, this.created_at, this.updated_at are not working
        // Quick fix: not to use them and update db colums after csv import
        DB::table('countries')->update([
            'created_at' => Carbon::now()->toString(),
            'updated_at' => Carbon::now()->toString(),
        ]);
    }
}
